"""
模型配置模型
"""

from sqlalchemy import Column, Integer, String, DateTime, Text, Boolean, JSON
from sqlalchemy.sql import func
from app.database import Base


class ModelConfig(Base):
    """模型配置表"""
    
    __tablename__ = "model_configs"
    
    id = Column(Integer, primary_key=True, index=True, comment="配置ID")
    name = Column(String(100), nullable=False, comment="配置名称")
    provider = Column(String(50), nullable=False, comment="模型提供商")
    model_name = Column(String(100), nullable=False, comment="模型名称")
    api_key = Column(Text, comment="API密钥")
    base_url = Column(String(500), comment="API基础URL")
    api_version = Column(String(50), comment="API版本")
    temperature = Column(String(10), default="0.7", comment="温度参数")
    max_tokens = Column(Integer, default=2000, comment="最大token数")
    top_p = Column(String(10), default="1.0", comment="Top-p参数")
    frequency_penalty = Column(String(10), default="0.0", comment="频率惩罚")
    presence_penalty = Column(String(10), default="0.0", comment="存在惩罚")
    timeout = Column(Integer, default=30, comment="超时时间（秒）")
    max_retries = Column(Integer, default=3, comment="最大重试次数")
    is_active = Column(Boolean, default=True, comment="是否激活")
    is_default = Column(Boolean, default=False, comment="是否默认")
    description = Column(Text, comment="配置描述")
    extra_config = Column(JSON, comment="额外配置")
    created_at = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), comment="更新时间")
    
    def __repr__(self):
        return f"<ModelConfig(id={self.id}, name='{self.name}', provider='{self.provider}')>"
